package com.szrt.zw.test.classes.controller;



import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.szrt.zw.test.base.BaseController;
import com.szrt.zw.test.base.BaseService;
import com.szrt.zw.test.classes.entity.ClassEntity;
import com.szrt.zw.test.classes.service.ClassService;
import com.szrt.zw.test.student.dto.SelectionDTO;


@Controller
@RequestMapping("/class")
public class ClassController extends BaseController<ClassEntity> {
   @Autowired
	private ClassService service;
  
   /**
	 * http://localhost:8080/ticket/central/user/*.do?id=1
	 */
	@Override
	public BaseService<ClassEntity> getBaseService() {
		return service;
	}
	@ResponseBody
	@RequestMapping("/findAllClass")
	public Map<String,Object> findAllClass(Integer page, Integer rows,String className){
		Integer before = (page -1)*rows;
		Integer after = rows;
		Map<String,Object> pageMap = new HashMap<String,Object>();
		pageMap.put("before", before);
		pageMap.put("after", after);
		 try {
			 if (null!=className && !"".equals(className.trim())) {
				 pageMap.put("className", className+"%");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		List<ClassEntity> list=service.findAllClass(pageMap);
		
		Map<String,Object> map=new HashMap<>();
		int  total =service.getTotalCounter(pageMap);
		map.put("total", total);
		map.put("rows",list);
		map.put("result","success");
		return map;
	}
	
	@ResponseBody
	@RequestMapping("/findAllSelectionDTO")
	public List<SelectionDTO> findAllSelectionDTO(){
		return service.findAllSelectionDTO();
	}
	
	
}